package com.s69.thymeleafdemo.controller;

import com.s69.thymeleafdemo.entity.Student;
import com.s69.thymeleafdemo.entity.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Controller
public class ThymeleafController {

    @GetMapping("/hello")
    public String hello(Model model) {
        model.addAttribute("username", "gyh");
        model.addAttribute("username1", "<h1>gyh</h1>");
        model.addAttribute("sex", 1);
        model.addAttribute("city", "yueyang");

        UserInfo user1 = new UserInfo(1, "李白", "123");
        UserInfo user2 = new UserInfo(2, "杜甫", "123");
        List<UserInfo> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);
        model.addAttribute("users", users);
        model.addAttribute("date", new Date());
        return "hello";
    }

    @GetMapping("/login")
    public String login(String username, String pass) {
        System.out.println(username);
        System.out.println(pass);
        System.out.println("exec login()");
        return "hello";
    }

    @GetMapping("/student")
    public String getList(Model model) {
        List<Student> list = Arrays.asList(
                new Student[]{
                        new Student(1, "张三","女",20, "计科1班"),
                        new Student(2, "李四","男",21, "计科2班"),
                        new Student(3, "李白","男",18, "计科3班")
                }
        );
        model.addAttribute("stus",list);
        return "hello";
    }
}
